Manon.icu

I'm here to make you a better developer by teaching you everything I know about building for the web.

Published 2021-04-20

React Lists

react 使用.map遍历并显示列表组件。

function SoccerPlayers() {
  const players = ['Messi', 'Ronaldo', 'Laspada']

  return (
    <div>
      {players.map((playerName) => (
        <SoccerPlayer key={playerName} name={playerName} />
      ))}
    </div>
  )
}

遍历输出的组件中key是必需的,因为它是用来唯一标识组件的。

Comments

No Comments!